"""
# -*- coding: utf-8 -*-
# @Time    : 2023/6/15 14:52
# @Author  : 王摇摆
# @FileName: DataPreview.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
import os
import torch
from torchvision import datasets, transforms

data_dir = "DogsVSCats"
# 定义了数据转换的字典 data_transform
data_transform = {x: transforms.Compose([transforms.Resize([64, 64]),
                                         transforms.ToTensor()]) for x in ["train", "valid"]}
# 定义了一个图像数据集字典 image_datasets
image_datasets = {x: datasets.ImageFolder(root=os.path.join(data_dir, x),
                                          transform=data_transform[x]) for x in ["train", "valid"]}

# 定义了一个数据加载器字典 dataloader
dataloader = {x: torch.utils.data.DataLoader(dataset=image_datasets[x],
                                             batch_size=16,
                                             shuffle=True)
              for x in ["train", "valid"]}

# X_example, y_example = next(iter(dataloader["train"]))

# # 从数据加载器中提取的一个批次的图像数据和对应的标签数据的长度
# print('===============输出一个batch中的个数==================')
# print(u"X_example 个数{}".format(len(X_example)))
# print(u"y_example 个数{}".format(len(y_example)))
#
# # 验证独热编码
# print('===============独热编码中的内容是==================')
# index_classes = image_datasets["train"].class_to_idx
# print(index_classes)
#
# # 将原始标签的结果存储在名为example_classes的变量中
# print('===============将标签结果存储在变量中==================')
# example_classes = image_datasets["train"].classes
# print(example_classes)
#
# # 用Matplotlib对一个批次的图片进行绘制
# print('===============将一个batch中的图片绘制出来==================')
# img = torchvision.utils.make_grid(X_example)
# img = img.numpy().transpose([1, 2, 0])
# print([example_classes[i] for i in y_example])
# plt.imshow(img)
# plt.show()
